package com.itxx.tcp;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.Scanner;

public class TcpSend1 {
    public static void main(String[] args) throws IOException {
        //tcp  是一种可靠的网络协议  他在通信的两端各建立一个Socket对象
        //通信之间要保证链接正常
        Scanner sc = new Scanner(System.in);
        //1.创建客户端Socket对象
        Socket socket = new Socket("127.0.0.1", 54322);
        //2.写输出流 传递对象
        OutputStream os = socket.getOutputStream();
        OutputStreamWriter osw = new OutputStreamWriter(os);
        //写数据
        while (true) {

            String s = sc.next();
            osw.write(s);
            osw.flush();
            if (s.equals("886")) {
                break;
            }
        }


        //3.释放资源
        socket.close();
        /*
        try(){
        }
        */
    }
}
